class Solution {
    public String convert(String s, int numRows) {
        //字符串的拼接
        // 当numrow为1，此时不进行转换
        if(numRows<=1){
            return s;
        }
        //转换成array，和len为了减小开销，提高效率
        char[] c = s.toCharArray();
        int len = s.length();
        //创建StringBuilder来存放，每一行的元素
        StringBuilder[] sbs = new StringBuilder[numRows];

        //初始化StringBuilder
        for(int i =0 ; i<sbs.length ; i++){
            sbs[i]=new StringBuilder();
        }
        //创建StringBuilder来存放结果
        StringBuilder re = new StringBuilder();
        //i++在内部操作
        for(int i =0 ; i<len ;){
            //从上往下,向StringBuilder中拼接元素
            for(int row = 0;row <numRows && i<len ; row++){
                sbs[row].append(c[i]);
                i++;
            }
            //从下往上,向StringBuilder中拼接元素
            for(int row =numRows-2 ;row >=1 && i<len; row--){
                sbs[row].append(c[i]);
                i++;
            }
        }
        for(StringBuilder sb:sbs ){
            re.append(sb);
        }
        return re.toString();
    }
}

public class MainClass {
    public static String stringToString(String input) {
        if (input == null) {
            return "null";
        }
        return Json.value(input).toString();
    }
    
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = in.readLine()) != null) {
            String s = stringToString(line);
            line = in.readLine();
            int numRows = Integer.parseInt(line);
            
            String ret = new Solution().convert(s, numRows);
            
            String out = (ret);
            
            System.out.print(out);
        }
    }
}